"use strict";
cc._RF.push(module, '6e0beD86ExDq5Qsxg+46csb', 'PlayerInfoViewUI');
// scripts/PlayerInfoViewUI.js

"use strict";

var e = require;
var t = module;
var o = exports;

var _ii,
    nn = void 0 && (void 0).__extends || (_ii = function ii(t, e) {
  return (_ii = Object.setPrototypeOf || {
    __proto__: []
  } instanceof Array && function (t, e) {
    t.__proto__ = e;
  } || function (t, e) {
    for (var o in e) {
      Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o]);
    }
  })(t, e);
}, function (t, e) {
  function o() {
    this.constructor = t;
  }

  _ii(t, e), t.prototype = null === e ? Object.create(e) : (o.prototype = e.prototype, new o());
}),
    rr = void 0 && (void 0).__awaiter || function (t, e, o, i) {
  return new (o || (o = Promise))(function (n, a) {
    function r(t) {
      try {
        l(i.next(t));
      } catch (e) {
        a(e);
      }
    }

    function s(t) {
      try {
        l(i["throw"](t));
      } catch (e) {
        a(e);
      }
    }

    function l(t) {
      var e;
      t.done ? n(t.value) : (e = t.value, e instanceof o ? e : new o(function (t) {
        t(e);
      })).then(r, s);
    }

    l((i = i.apply(t, e || [])).next());
  });
};

var oo = void 0 && (void 0).__decorate || function (e, t, a, n) {
  var i,
      o = arguments.length,
      s = o < 3 ? t : null === n ? n = Object.getOwnPropertyDescriptor(t, a) : n;
  if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) s = Reflect.decorate(e, t, a, n);else for (var r = e.length - 1; r >= 0; r--) {
    (i = e[r]) && (s = (o < 3 ? i(s) : o > 3 ? i(t, a, s) : i(t, a)) || s);
  }
  return o > 3 && s && Object.defineProperty(t, a, s), s;
};

Object.defineProperty(o, "__esModule", {
  value: !0
});

var a = e("BaseModuleUI"),
    n = e("NotifyEventType"),
    i = e("GlobalParams"),
    r = e("AssetsManager"),
    s = e("AudioManager"),
    l = e("CommonHelper"),
    _ = e("nameCfg"),
    c = e("AD"),
    d = cc._decorator,
    h = d.ccclass,
    u = d.property,
    p = function (e) {
  function t() {
    var t = null !== e && e.apply(this, arguments) || this;
    return t.player_head_sprite = null, t.player_name_label = null, t.now_level_icon = null, t.now_level_num = null, t.max_level_icon = null, t.max_level_num = null, t.data_info_list = [], t.win_schedule_num = null, t.head_view_ui = null, t.head_item = null, t.head_view_content = null, t;
  }

  return nn(t, e), t.prototype.initView = function () {
    e.prototype.initView.call(this), this.showPlayerInfo(), this.showLevelInfo(), this.showFightInfo(), this.showHeadViewInfo();
  }, t.prototype.OnClick = function (t) {
    var o = this;
    e.prototype.OnClick.call(this, t);
    var a = t.node.name,
        r = i.GlobalParams.PlayerInfo.value;

    switch (a) {
      case "update_name_btn":
        c["default"].getInstance().showVideo(function (e) {
          s["default"].playGameBGM(), e == c.ResultEnum.Success && (r.name = _["default"].nameList[l["default"].getRandomInt(0, _["default"].nameList.length - 1)], i.GlobalParams.PlayerInfo.value = r, o.emitEvent(n["default"].SEND_UPDATE_PLAYER_INFO), o.showPlayerInfo());
        });
        break;

      case "head_btn":
        this.head_view_ui.active = !0;
    }
  }, t.prototype.showPlayerInfo = function () {
    var e = i.GlobalParams.PlayerInfo.value;
    this.player_head_sprite.spriteFrame = r["default"].getInstance().getHeroHeadFrame("hero_" + e.head), this.player_name_label.string = "" + e.name;
  }, t.prototype.showLevelInfo = function () {
    var e = i.GlobalParams.PlayerInfo.value,
        t = Math.floor(e.level / 10);
    t = t > 6 ? 6 : t, this.now_level_icon.spriteFrame = r["default"].getInstance().getPlayerLevelExp(t), this.now_level_num.string = "Lv " + e.level;
    var o = Math.floor(e.max_level / 10);
    o = o > 6 ? 6 : o, this.max_level_icon.spriteFrame = r["default"].getInstance().getPlayerLevelExp(o), this.max_level_num.string = "Lv" + e.max_level;
  }, t.prototype.showFightInfo = function () {
    for (var e = i.GlobalParams.FightDataInfo.value, t = 0; t < this.data_info_list.length; t++) {
      this.data_info_list[t].string = "" + e.data_info[t];
    }

    0 == e.win_num ? this.win_schedule_num.string = "0" : this.win_schedule_num.string = 100 * Number((e.win_num / e.fight_num).toFixed(2)) + "%";
  }, t.prototype.showHeadViewInfo = function () {
    for (var e = i.GlobalParams.PlayerInfo.value, t = 1; t < 16; t++) {
      var o = null;
      this.head_view_content.children[t - 1] ? o = this.head_view_content.children[t - 1] : (o = cc.instantiate(this.head_item), this.head_view_content.addChild(o)), o.active = !0, o.getComponent(cc.Sprite).spriteFrame = r["default"].getInstance().getHeroHeadFrame("hero_" + t), o.children[1].active = -1 == e.have_head.indexOf(t) && !c["default"].getInstance().getGameTestVersion(), o.name = "head_" + t, o.on("click", this.chooseThisHead, this);
    }
  }, t.prototype.chooseThisHead = function (e) {
    var t = this;
    s["default"].ButtonSound();

    var o = e.node,
        a = o.name,
        n = Number(l["default"].getNameType(a, "head_")),
        r = function r() {
      var e = i.GlobalParams.PlayerInfo.value;
      -1 == e.have_head.indexOf(n) && e.have_head.push(n), e.head = n, i.GlobalParams.PlayerInfo.value = e, t.showPlayerInfo(), t.head_view_ui.active = !1;
    };

    o.children[1].active ? c["default"].getInstance().showVideo(function (e) {
      s["default"].playGameBGM(), e == c.ResultEnum.Success && r();
    }) : r();
  }, oo([u(cc.Sprite)], t.prototype, "player_head_sprite", void 0), oo([u(cc.Label)], t.prototype, "player_name_label", void 0), oo([u(cc.Sprite)], t.prototype, "now_level_icon", void 0), oo([u(cc.Label)], t.prototype, "now_level_num", void 0), oo([u(cc.Sprite)], t.prototype, "max_level_icon", void 0), oo([u(cc.Label)], t.prototype, "max_level_num", void 0), oo([u(cc.Label)], t.prototype, "data_info_list", void 0), oo([u(cc.Label)], t.prototype, "win_schedule_num", void 0), oo([u(cc.Node)], t.prototype, "head_view_ui", void 0), oo([u(cc.Node)], t.prototype, "head_item", void 0), oo([u(cc.Node)], t.prototype, "head_view_content", void 0), oo([h], t);
}(a["default"]);

o["default"] = p;

cc._RF.pop();